﻿using Grpc.Net.Client;
using Md.Demo.Rpc;
using Md.Demo.Service;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static Md.Demo.Service.Greeter;

namespace Md.Demo.API.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class InterviewController : ControllerBase
    {
        private readonly InterviewRpc _interviewRpc;
        public InterviewController(InterviewRpc interviewRpc)
        {
            _interviewRpc = interviewRpc;
        }

        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <param name="keyword">部门名称</param>
        /// <returns></returns>
        [HttpGet("getDepatmentList")]
        public async Task<IActionResult> GetDepatmentListAsync(string keyword = "")
        {
            var reply = await _interviewRpc.GetDepatmentListAsync(
                new GetListRequest
                {
                    KeyWord = keyword,
                });
            return Ok(reply);
        }
        /// <summary>
        /// 获取面试官列表
        /// </summary>
        /// <param name="keyword">面试官名称 手机或者邮箱</param>
        /// <returns></returns>
        [HttpGet("getInterviewerList")]
        public async Task<IActionResult> GetInterviewerListAsync(string keyword = "")
        {
            var reply = await _interviewRpc.GetInterviewerListAsync(
                new GetListRequest
                {
                    KeyWord = keyword,
                });
            return Ok(reply);
        }
        /// <summary>
        /// 获取职位列表
        /// </summary>
        /// <param name="status">职位状态</param>
        /// <param name="keyword">职位名称 职责或者 要求 </param>
        /// <param name="pageindx">页码</param>
        /// <param name="pagesize">每页显示条数</param>
        /// <returns></returns>
        [HttpGet("getJobList")]
        public async Task<IActionResult> GetJobListAsync(int status, string keyword = "", int pageindx = 1, int pagesize = 20)
        {
            var reply = await _interviewRpc.GetJobListAsync(
                new JobListRequest
                {
                    Status = status,
                    KeyWord = keyword,
                    PageIndex = pageindx,
                    PageSize = pagesize
                });
            return Ok(reply);
        }
        /// <summary>
        /// 创建/编辑职位
        /// </summary>
        /// <param name="postData"></param>
        /// <returns></returns>
        [HttpPost("createJob")]
        public async Task<IActionResult> CreateJobAsync([FromBody] CreateJobRequest postData)
        {
            var reply = await _interviewRpc.CreateJobAsync(postData);
            return Ok(reply);
        }
        /// <summary>
        /// 删除职位
        /// </summary>
        /// <param name="postData"></param>
        /// <returns></returns>
        [HttpPost("deleteJob")]
        public async Task<IActionResult> DeleteJobAsync([FromBody] DeleteRequest postData)
        {
            var reply = await _interviewRpc.DeleteJobAsync(postData);
            return Ok(reply);
        }

        /// <summary>
        /// 获取候选人列表  
        /// </summary>
        /// <param name="status">跟进状态 </param>
        /// <param name="jobId">职位id</param>
        /// <param name="keyword">候选人姓名 手机号  或者邮箱 </param>
        /// <param name="pageindx">页码 </param>
        /// <param name="pagesize">每页条数 </param>
        /// <returns></returns>
        [HttpGet("getStaffList")]
        public async Task<IActionResult> GetStaffListAsync(int status, string jobId = "", string keyword = "", int pageindx = 1, int pagesize = 20)
        {
            var reply = await _interviewRpc.GetStaffListAsync(
                new StaffListRequest
                {
                    JobId = jobId,
                    Status = status,
                    KeyWord = keyword,
                    PageIndex = pageindx,
                    PageSize = pagesize
                });
            return Ok(reply);
        }
        /// <summary>
        /// 创建/编辑候选人
        /// </summary>
        /// <param name="postData"></param>
        /// <returns></returns>
        [HttpPost("createStaff")]
        public async Task<IActionResult> CreateStaffAsync([FromBody] CreateStaffRequest postData)
        {
            var reply = await _interviewRpc.CreateStaffAsync(postData);
            return Ok(reply);
        }
        /// <summary>
        /// 删除候选人
        /// </summary>
        /// <param name="postData"></param>
        /// <returns></returns>
        [HttpPost("deleteStaff")]
        public async Task<IActionResult> DeleteStaffAsync([FromBody] DeleteRequest postData)
        {
            var reply = await _interviewRpc.DeleteStaffAsync(postData);
            return Ok(reply);
        }
        /// <summary>
        /// 获取面试列表 
        /// </summary>
        /// <param name="status">面试状态</param>
        /// <param name="staffId">候选人id</param>
        /// <param name="keyword">面试者名字</param>
        /// <param name="pageindx">页码 </param>
        /// <param name="pagesize">每页条数 </param>
        /// <returns></returns>
        [HttpGet("getInterviewList")]
        public async Task<IActionResult> GetInterviewListAsync(int status, string staffId = "", string keyword = "", int pageindx = 1, int pagesize = 20)
        {
            var reply = await _interviewRpc.GetInterviewListAsync(
                new InterviewListRequest
                {
                    StaffId = staffId,
                    Status = status,
                    KeyWord = keyword,
                    PageIndex = pageindx,
                    PageSize = pagesize
                });
            return Ok(reply);
        }
        /// <summary>
        /// 创建/编辑面试记录
        /// </summary>
        /// <param name="postData"></param>
        /// <returns></returns>
        [HttpPost("createInterview")]
        public async Task<IActionResult> CreateInterview([FromBody] CreateInterviewRequest postData)
        {
            var reply = await _interviewRpc.CreateInterview(postData);
            return Ok(reply);
        }
        /// <summary>
        /// 删除面试记录
        /// </summary>
        /// <param name="postData"></param>
        /// <returns></returns>
        [HttpPost("deleteInterview")]
        public async Task<IActionResult> DeleteInterviewAsync([FromBody] DeleteRequest postData)
        {
            var reply = await _interviewRpc.DeleteInterviewAsync(postData);
            return Ok(reply);
        }
    }
}
